﻿using Roton.Audio;
using Roton.Input;
using Roton.Video;
using Roton.Wrapper.ZZT;
using Roton.ZZT;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton
{
    public enum GameType
    {
        None,
        ZZT,
        SuperZZT
    }

    public class Game : IDisposable
    {
        IAudio audio;
        Context context;
        IInput input;
        Parameters parameters;
        EventTimer timer;
        IVideo video;

        public Game(GameType gameType, IVideo video, IAudio audio, IInput input)
        {
            IMemory memory;

            switch (gameType)
            {
                case GameType.ZZT:
                    memory = new ZZTMemoryWrapper();
                    parameters = ParameterDefaults.ZZT;
                    break;
                default:
                    throw new NotImplementedException();
            }

            if (video == null)
                video = new VideoNull();
            if (audio == null)
                audio = new AudioNull();
            if (input == null)
                input = new InputNull();
            this.video = video;
            this.audio = audio;
            this.input = input;

            timer = new EventTimer(71.2D);
            context = new Context(memory, video, audio, input, timer, parameters);
        }

        public void Dispose()
        {
            timer.Dispose();
        }

        public byte[] DumpMemory()
        {
            return context.Dump();
        }
    }
}
